class Solution
{
public:
    vector<vector<int>> permuteUnique(vector<int> &nums)
    {
        vector<vector<int>> result;
        perm(nums, 0, result);
        return result;
    }

    void perm(vector<int> &nums, int i, vector<vector<int>> &result)
    {
        if (i == nums.size() - 1)
        {
            result.push_back(nums);
            return;
        }
        for (int k = i; k < nums.size(); ++k)
        {
            bool repeat = false;
            for (int j = i; j < k; ++j)
            {
                if (nums[j] == nums[k])
                {
                    repeat = true;
                    break;
                }
            }
            if (repeat)
            {
                continue;
            }
            swap(nums[i], nums[k]);
            perm(nums, i + 1, result);
            swap(nums[i], nums[k]);
        }
    }
};